feat(error): add namespaced, serializable error domains - #7
Merged
Conversation
Adds a new `error` sub-export for defining error classes: domains are classes (so `instanceof` works against a whole domain, not just one error), error codes are namespaced via the existing `namespace` module, context merges domain defaults -> per-error defaults -> runtime context, and errors round-trip through JSON via `toJSON()`/`errors.parse()` with an `UnknownError` fallback for unregistered codes. Stack serialization defaults to `isDev` (new `src/lib/is-dev.ts` helper) and is configurable globally or per call. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Coverage Report for CI Build 30963464752Coverage increased (+0.05%) to 95.68%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
π - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
errorsub-export for defining namespaced, serializable error classes grouped into domains (namespacing via the existingnamespacemodule).instanceofworks against a whole domain (or sub-domain), not just a single error; domains are abstract and throw if instantiated directly.ErrorDomain.define()batch-defines one or more error classes at once, merging context in the order domain defaults β per-error defaults β runtime context.JSON.stringify()/errors.parse()(accepting a JSON string or an already-parsed object) via an exact-snapshot reconstruction, falling back toUnknownErrorfor unregistered codes; stack serialization defaults to a newisDevhelper (src/lib/is-dev.ts) and is configurable globally (errors.serialize.includeStack) or per call.package.json,jsr.json,.size-limit.json, and the root README's utilities table.Test plan
npm run test:unitβ 420 tests pass across the project, including 26 for the newerrormodulenpm run test:types/npm run test:lint/npm run test:formatnpm run test:build:sizeβ new module measures 868 B brotli, under its 875 B limit